package com.linsen.gateway.props;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @author zhaoyong
 * @date 2023/8/4
 */
@Data
@RefreshScope
@ConfigurationProperties(prefix = "linsen.gateway")
public class LinsenGatewayProperties {
    /**
     * 是否开启sa-token
     */
    private Boolean saReactorFilter = Boolean.TRUE;

    /**
     * 是否启用打印日志
     */
    private Boolean log = Boolean.FALSE;

    /**
     * 是否开启日志链路追踪
     */
    private Boolean trace = Boolean.FALSE;

    /**
     * 是否启用获取IP地址
     */
    private Boolean ip = Boolean.FALSE;

    /**
     * 是否启用增强模式
     */
    private Boolean enhance = Boolean.FALSE;

    /**
     * 是否启用网关鉴权模式
     */
    private Boolean preAuth = Boolean.FALSE;

    /**
     * 监控中心和swagger需要访问的url
     */
    private static final String[] ENDPOINTS = {
            "/",
            "/favicon.ico",
            "/oauth/**",
            "/actuator/**",
            "/v2/api-docs/**",
            "/swagger/api-docs",
            "/swagger-ui.html",
            "/doc.html",
            "/swagger-resources/**",
            "/webjars/**",
            "/druid/**",
            "/error/**",
            "/assets/**",
    };

    /**
     * 忽略URL，List列表形式
     */
    private List<String> ignoreUrl = new ArrayList<>();

    /**
     * 首次加载合并ENDPOINTS
     */
    @PostConstruct
    public void initIgnoreUrl() {
        Collections.addAll(ignoreUrl, ENDPOINTS);
    }
}
